//
//  YXScreenView+ListProtocol.swift
//  SortProject
//
//  Created by ALH000355 on 2021/9/8.
//

import Foundation
import UIKit
import SnapKit

extension YXScreenView: UICollectionViewDelegate ,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if section == 0 {
            return self.screenOneSectionlList.count
        }
        if section == 1 {
            return self.screenTwoSectionlList.count

        }
        return 0

    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 2
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cellString = "SwiftCollectionViewCell"
        let cell = collection.dequeueReusableCell(withReuseIdentifier: cellString, for: indexPath) as! YXScreenCell
        if indexPath.section == 0 {
            let obj = screenOneSectionlList[indexPath.item]
            cell.classModel = obj
        } else if indexPath.section == 1 {
            let obj = screenTwoSectionlList[indexPath.item]
            cell.classModel = obj
        }

        return cell
    }
//设置 区头和区尾
   func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    
        if kind == UICollectionView.elementKindSectionHeader  {
            var reusabView = UICollectionReusableView.init()

            let headerView:UICollectionReusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "SwiftHeaderCollectionReusableView", for: indexPath)
            for v in headerView.subviews{
                v.removeFromSuperview()
            }
            let heardLab = UILabel.init()
            heardLab.font = .systemFont(ofSize: 17)
            heardLab.textColor = .black
            headerView.addSubview(heardLab)
            
            heardLab.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.top.equalTo(15)
            }
            let hearTestArr = ["任务场景","任务类型","任务内容"]
            heardLab.text = hearTestArr[indexPath.section]
            reusabView = headerView
            return reusabView
       } else {
//        YXCollectionFooterView
            if indexPath.section == 1 {
                let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "YXCollectionFooterView", for: indexPath)
                return footerView
            } else {
                return UICollectionReusableView.init()
            }
       }
       
    }
//    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//    
//    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: collectionWidth, height: 26)
    }
    //footView是我单独封装出来的一个view。就是图中的 确定，重置按钮，和选择时间的按钮
     //尾部高度
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
        if section == 1 {
            return CGSize(width: self.frame.size.width, height: 80)
        }
        return CGSize(width: 0, height: 0)
    }
    //头部高度设置
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        
        return CGSize(width: collectionWidth, height: 50)
    }
    //设置两个cell的左右间距
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 12
    }
    
}
